// 引用由build.rs生成的protobuf代码
// war3.rs文件由build.rs在编译时生成到src/目录
include!("war3.rs");

use prost::Message;
use crate::error::War3Error;

/// 将War3Message编码为字节数组
/// 
/// # 参数
/// * `message` - 要编码的War3Message
/// 
/// # 返回
/// * `Result<Vec<u8>, War3Error>` - 编码后的字节数组或错误
pub fn encode_message(message: &War3Message) -> Result<Vec<u8>, War3Error> {
    let mut buf = Vec::new();
    message.encode(&mut buf)?;
    Ok(buf)
}

/// 从字节数组解码War3Message
/// 
/// # 参数
/// * `data` - 要解码的字节数组
/// 
/// # 返回
/// * `Result<War3Message, War3Error>` - 解码后的War3Message或错误
pub fn decode_message(data: &[u8]) -> Result<War3Message, War3Error> {
    Ok(War3Message::decode(data)?)
}